#include<vector>
#include<iostream>
using std::vector;

class Solution {
public:
    void moveZeroes(vector<int>& nums) {
        if (nums.size() < 2) return;
        int i = 0;
        int j = 0;
        while (true) {
            
            while (i < nums.size() && nums[i] != 0) {
                i++;
            }
            if (i >= nums.size()) break;
            j = i + 1;
            while (j < nums.size() && nums[j] == 0) {
                j++;
            }
            if (j >= nums.size()) break;
            //std::cout << i << ", " << j << "\n";
            exch(nums, i, j);
            
            
        }
        

    }

private:
    void exch(vector<int>& nums, int i, int j) {
        int tmp = nums[i];
        nums[i] = nums[j];
        nums[j] = tmp;
    }
};


int main() {
    int tmp;
    vector<int> nums;
    while (std::cin >> tmp) {
        nums.push_back(tmp);
    }
    for (auto n: nums) {
        std::cout << n << " ";
    }
    std::cout << "\n";
    Solution().moveZeroes(nums);
    for (auto n: nums) {
        std::cout << n << " ";
    }
    std::cout << "\n";
    return 0;
}